package com.example.demo.dao;

import com.example.demo.pojo.TestUser;
import com.example.demo.pojo.TestUserId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

public interface DaoUserTest extends JpaRepository<TestUser, TestUserId> {

    int countByUserIdAndTestId(String userId, String testId);
    TestUser findByUserIdAndTestId(String userId,String testId);
    int countByTestId(String testId);
    @Query(nativeQuery=true, value = "select sum(score) from test_user where  test_id=:name ")
    int sumByTestId(@Param("name") String name);
    @Query(nativeQuery=true, value = "select max(score) from test_user where  test_id=:name ")
    int maxByTestId(@Param("name") String name);
    @Query(nativeQuery=true, value = "select min(score) from test_user where  test_id=:name ")
    int minByTestId(@Param("name") String name);
    @Query(nativeQuery=true, value = "select count(*) from test_user where  test_id=:name and score>=:A and score<:B")
    int countAtoBByClassId(@Param("name") String name ,@Param("A") int min ,@Param("B") int max );
    @Query(nativeQuery=true, value = "select score from test_user where  test_id=:name order by score  asc" )
    List<Integer> getAllScore(@Param("name") String s);

}
